      <div class="templatemo-content-wrapper">
        <div class="templatemo-content">
          <ul class="nav nav-tabs mytabs">
        	 <li class="active"><a href="<?php echo site_url('nutrition/index/id/'.$nutrition['id'])?>">编辑配方</a></li>
		  	 <li><a href="<?=site_url()?>/nutrition/index">配方列表</a></li>
		  	 <li><a href="<?=site_url()?>/nutrition/add">添加配方</a></li>
		  </ul>
          <div class="row">
            <div class="col-md-12">
              <div class="table-responsive">
                 <form role="form" id="templatemo-preferences-form" onsubmit="return false;">
                 	<input type="hidden" id="id" value="<?php echo $nutrition['id']; ?>" />
                 	 <div class="row">
                 	   <div class="col-md-6 margin-bottom-15">
	              		<label for="firstName" class="control-label">配方图片</label>
	              		<input class="file-" type="file"  id="img" name="Filedata"/>
                		<input id="pic" name="pic" type="hidden" class="input" value="<?php echo $nutrition['image']; ?>">
                		<img id="img_product" src="http://7xj0kd.com2.z0.glb.qiniucdn.com/<?php echo $nutrition['image']; ?>" width="50px;"  height="50px;"/>
                	  </div>
                	</div>
                	<div class="row">
                  	  <div class="col-md-6 margin-bottom-15">
                    	<label for="firstName" class="control-label">配方名称</label>
                    	<input type="text" class="form-control" id="name" value="<?php echo $nutrition['name']; ?>">
                  	  </div>
                  	  <div class="col-md-6 margin-bottom-15">
                        <label for="lastName" class="control-label">可食部分(%)</label>
                          	<input type="text" class="form-control" id="keshi" value="<?php echo $nutrition['keshi']; ?>">
                       	</div>
                        </div>
                         <div class="row">
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="firstName" class="control-label">能量(千卡)</label>
                          	<input type="text" class="form-control" id="nengliang" value="<?php echo $nutrition['nengliang']; ?>">
                        	</div>
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="lastName" class="control-label">水分(克)</label>
                          	<input type="text" class="form-control" id="water" value="<?php echo $nutrition['water']; ?>">
                       	</div>
                        </div>
                         <div class="row">
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="firstName" class="control-label">蛋白质(克)</label>
                          	<input type="text" class="form-control" id="danbaizhi" value="<?php echo $nutrition['danbaizhi']; ?>">
                        	</div>
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="lastName" class="control-label">脂肪(克)</label>
                          	<input type="text" class="form-control" id="zhifang" value="<?php echo $nutrition['zhifang']; ?>">
                       	</div>
                        </div>
                         <div class="row">
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="firstName" class="control-label">膳食纤维(克)</label>
                          	<input type="text" class="form-control" id="xianwei" value="<?php echo $nutrition['xianwei']; ?>">
                        	</div>
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="lastName" class="control-label">碳水化物(克)</label>
                          	<input type="text" class="form-control" id="tanshui" value="<?php echo $nutrition['tanshui']; ?>">
                       	</div>
                        </div>
                         <div class="row">
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="firstName" class="control-label">维生素A(微克)</label>
                          	<input type="text" class="form-control" id="weiA" value="<?php echo $nutrition['weiA']; ?>">
                        	</div>
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="lastName" class="control-label">维生素B1(毫克)</label>
                          	<input type="text" class="form-control" id="weiB1" value="<?php echo $nutrition['weiB1']; ?>">
                       	</div>
                        </div>
                         <div class="row">
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="firstName" class="control-label">维生素B2(毫克)</label>
                          	<input type="text" class="form-control" id="weiB2" value="<?php echo $nutrition['weiB2']; ?>">
                        	</div>
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="lastName" class="control-label">烟酸(毫克)</label>
                          	<input type="text" class="form-control" id="yansuan" value="<?php echo $nutrition['yansuan']; ?>">
                       	</div>
                        </div>
                         <div class="row">
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="firstName" class="control-label">维生素E(毫克)</label>
                          	<input type="text" class="form-control" id="weiE" value="<?php echo $nutrition['weiE']; ?>">
                        	</div>
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="lastName" class="control-label">钠(毫克)</label>
                          	<input type="text" class="form-control" id="na" value="<?php echo $nutrition['na']; ?>">
                       	</div>
                        </div>
                         <div class="row">
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="firstName" class="control-label">钙(毫克)</label>
                          	<input type="text" class="form-control" id="ca" value="<?php echo $nutrition['ca']; ?>">
                        	</div>
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="lastName" class="control-label">铁(毫克)</label>
                          	<input type="text" class="form-control" id="fe" value="<?php echo $nutrition['fe']; ?>">
                       	</div>
                        </div>
                         <div class="row">
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="firstName" class="control-label">维生素C(毫克)</label>
                          	<input type="text" class="form-control" id="weiC" value="<?php echo $nutrition['weiC']; ?>">
                        	</div>
                        	<div class="col-md-6 margin-bottom-15">
                          	<label for="lastName" class="control-label">胆固醇(毫克)</label>
                          	<input type="text" class="form-control" id="dangu" value="<?php echo $nutrition['dangu']; ?>">
                 	  </div>
                 	</div>
	              	<div class="row templatemo-form-buttons">
	                	<div class="col-md-12">
	                	  <button type="submit" class="btn btn-primary" id="submit_btn">修改</button>
	               	 </div>
                	</div>
                </form>
              </div>
            </div>
          </div>
        </div>
      </div>
<script>
	$(document).ready(function() {
		$('#img').ajaxfileupload({
				'action' : '<?php echo site_url('up/up_pic')?>',
				'params' : {
					'path' : 'product/pic'
				},
				onStart: function() {

				},
				'onComplete' : function(response) {
					if ( typeof response === 'string') {
						var files = response.replace(/\\/g, '/');
						$("#img_product").attr("src",'http://7xj0kd.com2.z0.glb.qiniucdn.com/'+files);
						$("#pic").val(files);
						alert("上传成功！");
					} else {
						alert("上传的文件格式不正确");
					}
				}
			});

		$("#submit_btn").click(function() {
			var id = $("#id").val();
      var image = $("#pic").val();
			var name = $("#name").val();
			var keshi = $("#keshi").val();
      var nengliang = $("#nengliang").val();
      var water = $("#water").val();
      var danbaizhi = $("#danbaizhi").val();
      var zhifang = $("#zhifang").val();
      var xianwei = $("#xianwei").val();
      var tanshui = $("#tanshui").val();
      var weiA = $("#weiA").val();
      var weiB1 = $("#weiB1").val();
      var weiB2 = $("#weiB2").val();
      var yansuan = $("#yansuan").val();
      var weiE = $("#weiE").val();
      var na = $("#na").val();
      var ca = $("#ca").val();
      var fe = $("#fe").val();
      var weiC = $("#weiC").val();
      var dangu = $("#dangu").val();

			if(name == ''){
				alert('名字不能为空')
				return;
			}

			$.ajax({
				url : '<?php echo site_url('nutrition/save')?>',
				type : "post",
				async : false,
				data : {
					'id' : id,
					'image' : image,
					'name' : name,
					'keshi' : keshi,
          'nengliang' : nengliang,
          'water' : water,
          'danbaizhi' : danbaizhi,
          'zhifang' : zhifang,
          'xianwei' : xianwei,
          'tanshui' : tanshui,
          'weiA' : weiA,
          'weiB1' : weiB1,
          'weiB2' : weiB2,
          'yansuan' : yansuan,
          'weiE' : weiE,
          'na' : na,
          'ca' : ca,
          'fe' : fe,
          'weiC' : weiC,
          'dangu' : dangu
				},
				dataType : "json",
				success : function(data) {
					if(data.code)
					{
						alert(data.msg);
						//window.location.reload();
					}else{
						alert(data.msg);
					}

				}
			});
		});
	});
</script>
